package com.ruoyi.web.controller.system;

import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
import javax.validation.constraints.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.vo.ZsyyOrderVo;
import com.ruoyi.system.bo.ZsyyOrderQueryBo;
import com.ruoyi.system.bo.ZsyyOrderAddBo;
import com.ruoyi.system.bo.ZsyyOrderEditBo;
import com.ruoyi.system.service.IZsyyOrderService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import springfox.documentation.annotations.ApiIgnore;

/**
 * 服务订单管理Controller
 *
 * @author wangghua
 * @date 2021-07-14
 */
@ApiIgnore
@Api(value = "服务订单管理控制器", tags = {"服务订单管理管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/system/serviceOrder")
public class ZsyyOrderController extends BaseController {

    private final IZsyyOrderService iZsyyOrderService;

    /**
     * 查询服务订单管理列表
     */
    @ApiOperation("查询服务订单管理列表")
    @PreAuthorize("@ss.hasPermi('system:serviceOrder:list')")
    @GetMapping("/list")
    public TableDataInfo<ZsyyOrderVo> list(@Validated ZsyyOrderQueryBo bo) {
        return iZsyyOrderService.queryPageList(bo);
    }

    /**
     * 导出服务订单管理列表
     */
    @ApiOperation("导出服务订单管理列表")
    @PreAuthorize("@ss.hasPermi('system:serviceOrder:export')")
    @Log(title = "服务订单管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<ZsyyOrderVo> export(@Validated ZsyyOrderQueryBo bo) {
        List<ZsyyOrderVo> list = iZsyyOrderService.queryList(bo);
        ExcelUtil<ZsyyOrderVo> util = new ExcelUtil<ZsyyOrderVo>(ZsyyOrderVo.class);
        return util.exportExcel(list, "服务订单管理");
    }

    /**
     * 获取服务订单管理详细信息
     */
    @ApiOperation("获取服务订单管理详细信息")
    @PreAuthorize("@ss.hasPermi('system:serviceOrder:query')")
    @GetMapping("/{id}")
    public AjaxResult<ZsyyOrderVo> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("id") Long id) {
        return AjaxResult.success(iZsyyOrderService.queryById(id));
    }

    /**
     * 新增服务订单管理
     */
    @ApiOperation("新增服务订单管理")
    @PreAuthorize("@ss.hasPermi('system:serviceOrder:add')")
    @Log(title = "服务订单管理", businessType = BusinessType.INSERT)
    @RepeatSubmit
    @PostMapping()
    public AjaxResult<Void> add(@Validated @RequestBody ZsyyOrderAddBo bo) {
        return toAjax(iZsyyOrderService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改服务订单管理
     */
    @ApiOperation("修改服务订单管理")
    @PreAuthorize("@ss.hasPermi('system:serviceOrder:edit')")
    @Log(title = "服务订单管理", businessType = BusinessType.UPDATE)
    @RepeatSubmit
    @PutMapping()
    public AjaxResult<Void> edit(@Validated @RequestBody ZsyyOrderEditBo bo) {
        return toAjax(iZsyyOrderService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 完成服务
     */
    @ApiOperation("完成服务")
    @PreAuthorize("@ss.hasPermi('system:serviceOrder:serviceOK')")
    @Log(title = "服务订单管理" , businessType = BusinessType.DELETE)
    @GetMapping("/serviceOK/{id}")
    public AjaxResult<Void> serviceOK(@NotEmpty(message = "订单id不能为空")
                                       @PathVariable Long id) {
        return toAjax(iZsyyOrderService.serviceOK(id) ? 1 : 0);
    }
    /**
     * 删除服务订单管理
     */
    @ApiOperation("删除服务订单管理")
    @PreAuthorize("@ss.hasPermi('system:serviceOrder:remove')")
    @Log(title = "服务订单管理" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] ids) {
        return toAjax(iZsyyOrderService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
